﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Globalization;
using System.Windows.Forms;



namespace Benchmark_System {
    class Run {

        static BenchmarkSystem bs = new BenchmarkSystem("Runs.txt");
        static Quries q = new Quries();


        public static void Main(String[] args) {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new GUI());
            //q.getAllUsers();

            //Console.WriteLine("ON!");
            //Execute();
        }
        /// <summary>
        /// Instantiates three jobs with random lenght.
        /// </summary>
        public static void RunNow() {

            Job job0 = new Job(new Random().Next(1, 10), new Random().Next(1, 5), Job.JobState.QUEUED, s => "Hans");
            bs.Submit(job0, new Owner("Hans"));

            Job job1 = new Job(new Random().Next(1, 10), new Random().Next(1, 5), Job.JobState.QUEUED, s => "Søren");
            bs.Submit(job1, new Owner("Søren"));

            Job job2 = new Job(new Random().Next(1, 10), new Random().Next(1, 5), Job.JobState.QUEUED, s => "Raz");
            bs.Submit(job2, new Owner("Raz"));

            //Console.Out.Write("Data: " + job0.id + " - ");
            Console.Out.WriteLine("Jobs in scheduler: " + bs.Status().Count());
        }
        /// <summary>
        /// Creates two threads, one adding jobs and one executing jobs.
        /// </summary>
        public static void Execute() {

            Thread addJobs = new Thread(() => { 
                //add jobs every 0.05...2 seconds
                while (true) { RunNow(); Thread.Sleep(new Random().Next(50, 2000)); } 
            });

            Thread exeJobs = new Thread(() => {
                //execute jobs every 2 seconds
                while (true) { bs.ExecuteAll(); Thread.Sleep(2000); }
            });

            addJobs.Start();
            exeJobs.Start();

            //Console.ReadKey();
            //Exe();

        }
    }
}
